import React, { Component } from 'react';
import {
    View,
    Text,
    TextInput,
    StyleSheet,
    TouchableOpacity
} from 'react-native';

class Input extends Component {
    state = {};

    constructor(props) {
        super(props);

        this.state = {

            TextInputText: ''
        }

    }


    render() {
        return (
            <View >
                <View style={styles.textField}>
                    <TextInput
                        autoCapitalize='none'
                        autoCorrect={false}
                        blurOnSubmit={true}
                        style={styles.edit}
                        underlineColorAndroid='transparent'
                        placeholder={'请输入' + this.props.navigation.state.params.title}
                        keyboardType='numeric'
                        selectTextOnFocus={false}
                        onChangeText={(text) => this.onChangeText(text)}
                    />
                    {/* <TouchableOpacity onPress={this.clickBtn} style={{ height: 44, flex: 1, }}> */}
                    {/* </TouchableOpacity> */}
                </View>
                <View style={{marginTop:30,marginLeft:30,marginRight:30,height:44,alignItems:'center',borderColor:'gray',borderWidth:0.5}}>
                    <Text onPress={this.clickBtn.bind(this)} style={{ height: 44, lineHeight: 44 }}>确定</Text>
                </View>
            </View>
        );
    }

    clickBtn() {

        var str = this.state.TextInputText;
        if(!str){
            alert('请输入')
            return;
        }
        this.props.navigation.state.params.callback(str);
        this.props.navigation.goBack();
    }

    onChangeText = (text) => {

        this.setState({
            TextInputText: text,
        })

    }
}

const styles = StyleSheet.create({
    textField: {
        height: 44,
        // flexDirection: 'row',
        // alignItems: 'center',
        borderBottomWidth: 1,
        borderBottomColor: '#ddd'
    },
    edit: {
        flex: 1,
        fontSize: 17,
        height: 44
    },

});

export default Input;
